import { _decorator, Component, find, input, Input, EventKeyboard, KeyCode, SpriteFrame, director, } from 'cc';
import YangLeGeYang_GameManager from '../../SubGame/YangLeGeYang/Script/Manager/YangLeGeYang_GameManager';
import ChengYu_Main from '../../SubGame/ChengYu/game/ChengYu/Script/XXL/Manager/ChengYu_Main';
import JiuJiuXiaoDongWu_GameManager from '../../SubGame/JiuJiuXiaoDongWu/Script/JiuJiuXiaoDongWu_GameManager';
import { LianLianKan } from '../../SubGame/LianLianKan/script/LianLianKan';
import DaoShuiPaiXu_GameManager from '../../SubGame/DaoShuiPaiXu/Script/DaoShuiPaiXu_GameManager';
import RuntimeScrollSaverSimple, { GLOBAL_MAP_NAME } from '../UI/RuntimeScrollSaver';
import UI from './UI';
import SandBlast_LosePanel from '../../SubGame/SandBlast/Script/SandBlast_LosePanel';
import { Game } from '../../SubGame/SandBlast/Game';
import { HexagonJenga_main } from '../../SubGame/HexagonJenga/script/HexagonJenga_main';

const { ccclass, property } = _decorator;

@ccclass('SSS_InputManager')
export default class SSS_InputManager extends Component {
        static Instance: SSS_InputManager;

        onLoad() {
                SSS_InputManager.Instance = this;

                input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
                // input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
        }

        async onKeyDown(event: EventKeyboard) {
                if (event.keyCode == KeyCode.ARROW_UP || event.keyCode == KeyCode.KEY_W) {
                        // console.log(`up`);
                        // SS_GameManager.Instance.上一关();
                }
                if (event.keyCode == KeyCode.ARROW_DOWN || event.keyCode == KeyCode.KEY_S) {
                        // console.log(`down`);
                        // SS_GameManager.Instance.下一关();
                }
                if (event.keyCode == KeyCode.ARROW_LEFT || event.keyCode == KeyCode.KEY_A) {
                        // console.log(`left`);
                        // SS_GameManager.Instance.上一关();
                        YangLeGeYang_GameManager.Instance?.上一关();
                        ChengYu_Main.Instance?.上一关();

                        JiuJiuXiaoDongWu_GameManager.Instance?.上一关();
                        LianLianKan.Instance?.上一关();

                        DaoShuiPaiXu_GameManager.Instance?.上一关();

                        // LianLianKan_GameData.CurrentLevelIndex--;
                        // let currentSceneName = director.getScene().name;
                        // director.loadScene(`LianLianKan_Game_Scene`);
                }
                if (event.keyCode == KeyCode.ARROW_RIGHT || event.keyCode == KeyCode.KEY_D) {
                        console.log(`right`);
                        // SS_GameManager.Instance.下一关();

                        YangLeGeYang_GameManager.Instance?.下一关();
                        ChengYu_Main.Instance?.下一关();

                        JiuJiuXiaoDongWu_GameManager.Instance?.下一关();
                        LianLianKan.Instance?.下一关();

                        DaoShuiPaiXu_GameManager.Instance?.下一关();

                        // LianLianKan_GameData.CurrentLevelIndex++;
                        // let currentSceneName = director.getScene().name;
                        // director.loadScene(`LianLianKan_Game_Scene`);
                }

                if (event.keyCode == KeyCode.SPACE) {
                        // console.log(`空格`);

                        HexagonJenga_main.Instance.showWin();

                        // Game.instance.overGame();

                        // UI.Instance.CreatePanel_sub(`SandBlast_Prefab`, `UI/SandBlast_LosePanel`, SandBlast_LosePanel);

                        // console.log(`GLOBAL_MAP_NAME`, GLOBAL_MAP_NAME);

                        // JiuJiuXiaoDongWu_GameData.fitToScreenWithRotation(JiuJiuXiaoDongWu_GameManager.Instance.container);

                        // LianLianKan.Instance.onVictory();
                }

                if (event.keyCode == KeyCode.ESCAPE) {
                        // SS_UIManager.Instance.CreatePanel(`UI/SettingPanel`, SettingPanel);
                }
                if (event.keyCode == KeyCode.NUM_1) {
                        console.log("num1");

                        HexagonJenga_main.Instance.showLoseView();


                        // RuntimeScrollSaverSimple.Instance.保存()

                        // RuntimeScrollSaverSimple.Instance.读取()
                        // JiuJiuXiaoDongWu_GameData.centerHorizontally(JiuJiuXiaoDongWu_GameManager.Instance.container);
                        // SS_GameManager.Instance.成功()
                        // UI.Instance.CreatePanel_sub(`TurkishTetris_Prefab`, `UI/TurkishTetris_LosePanel`, TurkishTetris_LosePanel);
                }
                if (event.keyCode == KeyCode.NUM_2) {
                        console.log("num2");
                        // SS_GameManager.Instance.失败()
                        // RuntimeScrollSaverSimple.Instance.保存()
                        RuntimeScrollSaverSimple.Instance.读取()
                }
                if (event.keyCode == KeyCode.NUM_3) {
                        // console.log("num3");
                        // SS_AudioManager.Instance.pause();
                }
                if (event.keyCode == KeyCode.NUM_4) {
                        // console.log("num4");
                        // SS_AudioManager.Instance.resume();
                }
        }

        // onKeyUp(event: EventKeyboard) { }
}